﻿using System;
using System.Collections.Generic;
using System.Text;

namespace VMExplorer.MemoryObjects
{
  class ActxObject : GenericMemoryObject
  {
    #region Construction

    private ActxObject (SafeProcessHandle hProcess, MemoryAddress baseAddress, string name)
      : base (hProcess, baseAddress, name, RegionUsage.System)
		{
		}

		public static IEnumerable<IMemoryObject> Create (SafeProcessHandle hProcess, MemoryAddress baseAddress, string name)
    {
      List<IMemoryObject> memObjects = new List<IMemoryObject>();
      if (baseAddress.IsValid)
      {
        #region :: Activation context ::

        ActxObject hw = new ActxObject(hProcess, baseAddress, name);
        memObjects.Add(hw);

        #endregion
      }
      return memObjects;
    }

    #endregion
    #region Scan rule

    public static void InstallScanRule (Scanner scan)
    {
      scan.NextRegion += delegate (object sender, Scanner.NextRegionEventArgs e)
      {
        if (e.Handled) return;

				Int32 sig = RemoteReader.ReadInt32 (e.ProcessHandle, e.Range.Start);
        if (sig == /*'Actx'*/0x78746341)
        {
					e.MemObjects.Add (new ActxObject (e.ProcessHandle, e.Range.Start, "Unknown Actx"));
          e.Handled = true;
        }
      };
    }

    #endregion
  }
}
